package com.imageim.yimirror.common.ui.face;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import com.sensetime.stmobileapi.STMobile106;

/**
 * Created by Bruce.Zhou on 2017/12/7.
 */

public class FaceDetectView extends View  {

    private Paint paint;
    private STMobile106[] faceInfoList;
    private boolean isDrawing = true;
    private Canvas canvas;

    public FaceDetectView(Context context) {
        super(context);
        init();
    }

    public FaceDetectView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FaceDetectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void setFaceInfoList(STMobile106[] faceInfoList) {
        this.faceInfoList = faceInfoList;
    }

    private void init() {
        paint = new Paint();
        paint.setStrokeWidth(8);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GREEN);
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        this.canvas = canvas;
        canvas.drawRect(new Rect(0, 0, 1080, 1080), paint);
        if (faceInfoList != null && faceInfoList.length > 0) {
            for (int i = 0; i < faceInfoList.length; i++) {
                STMobile106 faceInfo = faceInfoList[i];
                canvas.drawRect(faceInfo.getRect(), paint);
            }
        }
    }



}
